#coding:utf-8

# --------- 基本方法 ------------
class Matrix(object):
    # ------- 初始化 ----------
    def __init__(this,*arg):
        arg = list(arg)
        row = len(arg)
        if row <= 0:
            raise ValueError('矩阵至少有一行!')
        col = len(arg[0])
        for __row in arg:
            if len(__row)!= col:
                raise ValueError('构造矩阵的矢量维度必须相等!')

        this.row = row #行数
        this.col = col #列数
        this._data = arg

    # 打印方法
    def __str__(this):
        return '\n'.join(map(str,[ this.getRow(r) for r in xrange(0,this.row) ]))

    # 获取参数
    def __getitem__(this,n):
        # 返回一个新的数组，避免存储被修改
        return list(this._data[n])

    # 获取某个值
    def get(this,m,n):
        return this[m][n]

    # 获取一行
    def getRow(this,m):
        return list(this[m])

    # 获取一列
    def getCol(this,n):
        return [ this[r][n] for r in range(0,this.row) ]        

    # 设定某格的数值
    def set(this,m,n,v):
        this._data[m][n] = v
        return this



# 测试脚本
def test():
    m1 = Matrix([1,0,0],[0,1,0],[0,0,1])

    # print(m1);
    # print(m1[2]);
    # m1[2].append(1);
    # print(m1[2]);
    # print(m1[2]);
    print(m1.getCol(1));
    pass

if __name__=='__main__':
    import sys
    test()